Telegram Group & Telegram Channel
🎓 Задача по Python #49

Описание:


Напишите функцию sum_range(start, end), которая суммирует все целые числа от значения «start» до величины «end» включительно.
Если пользователь задаст первое число большее чем второе, просто поменяйте их местами.

При решении удобно воспользоваться встроенными функциями range() и sum().

Решение:

def sum_range(start, end):
if start > end:
end, start = start, end
return sum(range(start, end + 1))

# Тесты
print(sum_range(2, 12))
print(sum_range(-4, 4))
print(sum_range(3, 2))

Результат выполнения:

77
0
5

Свой вариант решения в комментарии 💬

#задачи



tg-me.com/pythonturboru/564
Create:
Last Update:

🎓 Задача по Python #49

Описание:


Напишите функцию sum_range(start, end), которая суммирует все целые числа от значения «start» до величины «end» включительно.
Если пользователь задаст первое число большее чем второе, просто поменяйте их местами.

При решении удобно воспользоваться встроенными функциями range() и sum().

Решение:

def sum_range(start, end):
if start > end:
end, start = start, end
return sum(range(start, end + 1))

# Тесты
print(sum_range(2, 12))
print(sum_range(-4, 4))
print(sum_range(3, 2))

Результат выполнения:

77
0
5

Свой вариант решения в комментарии 💬

#задачи

BY Python Turbo. Уютное сообщество Python разработчиков.




Share with your friend now:
tg-me.com/pythonturboru/564

View MORE
Open in Telegram


Python Turbo Уютное сообщество Python разработчиков Telegram | DID YOU KNOW?

Date: |

Telegram has exploded as a hub for cybercriminals looking to buy, sell and share stolen data and hacking tools, new research shows, as the messaging app emerges as an alternative to the dark web.An investigation by cyber intelligence group Cyberint, together with the Financial Times, found a ballooning network of hackers sharing data leaks on the popular messaging platform, sometimes in channels with tens of thousands of subscribers, lured by its ease of use and light-touch moderation.

Telegram announces Search Filters

With the help of the Search Filters option, users can now filter search results by type. They can do that by using the new tabs: Media, Links, Files and others. Searches can be done based on the particular time period like by typing in the date or even “Yesterday”. If users type in the name of a person, group, channel or bot, an extra filter will be applied to the searches.

Python Turbo Уютное сообщество Python разработчиков from ua


Telegram Python Turbo. Уютное сообщество Python разработчиков.
FROM USA